package com.yowasa.xiuxian.engine.battle.strategy;

import com.yowasa.xiuxian.annoations.Buff;
import com.yowasa.xiuxian.engine.battle.buff.BuffInterface;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

@Component
@Order(1000)
public class BaseDefendStrategy extends CalAbility implements DefendStrategy {
    @Override
    public void limit(UserBO user) {
        return;
    }

    @Override
    public String limitDesc() {
        return "无";
    }

    @Override
    public String desc() {
        return "普通防御";
    }

    @Override
    public int defend(UserBattleContent user,UserBattleContent battleUser,BattleStrategy bs, int dmg, BattleContent content) {
        if (bs instanceof BaseBattleStrategy) {
            //物理伤害低段位无伤
            if (dmg < 5) {
                return 0;
            }
        }
        AtomicInteger a = new AtomicInteger(dmg);
        user.getBuff().entrySet().forEach(e -> {
            BuffInterface buff = BattleStrategyEngine.buffMap.get(e.getKey());
            if (buff.getClass().getAnnotation(Buff.class).type() == 2){
                a.set(buff.defendBuffAction(user, battleUser, a.get()));
            }
        });
        return a.get();
    }


    @Override
    public boolean check(UserBattleContent user, BattleStrategy bs, BattleContent content) {
        return true;
    }


    @Override
    public ElementEnum getElement() {
        return null;
    }
}
